package com.marketlive.util;

import java.util.List;


/*
(C) Copyright MarketLive. 2006. All rights reserved.
MarketLive is a trademark of MarketLive, Inc.
Warning: This computer program is protected by copyright law and international treaties.
Unauthorized reproduction or distribution of this program, or any portion of it, may result
in severe civil and criminal penalties, and will be prosecuted to the maximum extent
possible under the law.
*/

/**
 * Provides utilities for {@link String}, {@link List}, and array conversion.
 */
public abstract class StringUtil {

  /**
   * Converts a string array to a comma-delimited string.
   *
   * @param array an array of string values
   * @return a comma-delimited string
   */
  public static String arrayToString(String[] array) {

    StringBuffer value = new StringBuffer();

    for (int i = 0; i < array.length; i++) {

      if (i > 0)
        value.append(',');

      value.append(array[i]);
    }

    return value.toString();
  }

  /**
   * Converts a string list to a comma-delimited string.
   *
   * @param list a list of string values
   * @return a comma-delimited string
   */
  public static String listToString(List list) {

    StringBuffer value = new StringBuffer();

    for (int i = 0; i < list.size(); i++) {

      if (i > 0)
        value.append(',');

      value.append(list.get(i));
    }

    return value.toString();
  }
}
